%% import data from .out files
% 
[all_wind,all_rb,fir_wind,fir_rb]=JOBdata('1133');
% 1  2   3  4   5  6   7   8   9  10 11 12  13    14 15 16  17  18 19
% m1,m2,Lx,ecc0,a,tb0,mt1,mt2,kw,kw2,mx,mx2,eccx,tbx,f,nnn,uuu,m_tr,i
% m1,m2,Lx,ecc0,a,tb0,mt1,mt2,kw,kw2,mx,mx2,eccx,tbx,f,m_transferrate,b_iso,m_tr,i
% 20 \delta T
% load('D:\study\bsegit\bse-ng\JOB20201117DATA.mat')



%% initial parameters
global  ge AllmassNUM M1MAX M1MIN...
    CHAbeamingFlag SFR qNUM aNUM minLx maxLx alpha eddfac
alpha=2.7;
% tmax=1d4*1d6; % in units of year
AllmassNUM=1d3;
M1MAX=150;
M1MIN=2;
SFR=GetSFR(50,alpha,0.535,0,M1MIN,5);
% SFR=10.6984;
qNUM=93;
aNUM=100;
yearsc=3.1557d+07;
Msun=1.9891d30;
minLx=39;
maxLx=48;
% xi=Mdot/(sum(sum(data(:,1:2)))/tmax)/tmax*1d6;
CHAbeamingFlag=0;
eddfac=1d4;
%% delete some useless data

[all_rb_1,all_wind_1]=DELallrbwind(all_rb,all_wind);



%% all in all. ONE for ALL!!!
allinall=[all_rb_1;all_wind_1];


%% mass _tb 
xge=200;
yge=100;


plot_lx_tb_gedian_paper(allinall,xge,yge);
% SETplot(' Lx-Porb-total')

% plot_mass_tb_gedian_paper(allinall,xge,yge);
% SETplot(' M2-Porb-total')
% plot_mass_tb_gedian_paper(all_rb_1(all_rb_1(:,10)==14,:),xge,yge);
% SETplot(' M2-Porb-BH-RLOF')
% 
% plot_mass_tb_gedian_paper(all_wind_1(all_wind_1(:,10)==14,:),xge,yge);
% SETplot(' M2-Porb-BH-wind')
% 
% plot_mass_tb_gedian_paper(all_rb_1(all_rb_1(:,10)==13,:),xge,yge);
% SETplot(' M2-Porb-NS-RLOF')
% 
% plot_mass_tb_gedian_paper(all_wind_1(all_wind_1(:,10)==13,:),xge,yge);
% % ylim([2 4.8 ])
% SETplot(' M2-Porb-NS-wind')

%% XLF swartz2011
ge=50;
% plot_Lx_NNsum_gedian(allinall,beaming);
% hold on
% OBSplot(1)
% FITplot_swartz2011(1);
% clear opt
% opt.XLabel='log10(Luminosity) / log10(erg/s)';
% opt.YLabel='log10(Number of ULX)';
% % opt.Title='Luminosity Function';
% opt.Legend={'Total BPS','Obsevation'...
%     'Swartz et al. (2011)'};
% opt.Markers = {'', 's',''};
% opt.LineStyle = {'-', 'none','--'};
% 
% color=[[0 0.4470 0.7410];[0.6350 0.0780 0.1840];[0.5 0.5 0]];
% opt.Colors=color;
% % opt.Ylim=[0 3d2];
% opt.YScale='linear';
% opt.XLim=[39 41];
% opt.YLim=[0 2];
% opt.LegendBox='on';
% % opt.FileName="MAINLuminosity Function.jpg";
% setPlotProp(opt);
% hold off
%% plot Lx_porb again
SETplot(' Lx-Porb-total')
plot_lx_tb_gedian_paper(allinall,xge,yge);
SETplot(' Lx-Porb-total')
plot_lx_tb_gedian_paper(all_rb_1(all_rb_1(:,10)==14,:),xge,yge);
SETplot(' Lx-Porb-BH-RLOF')

plot_lx_tb_gedian_paper(all_wind_1(all_wind_1(:,10)==14,:),xge,yge);
SETplot(' Lx-Porb-BH-wind')

plot_lx_tb_gedian_paper(all_rb_1(all_rb_1(:,10)==13,:),xge,yge);
SETplot(' Lx-Porb-NS-RLOF')

plot_lx_tb_gedian_paper(all_wind_1(all_wind_1(:,10)==13,:),xge,yge);
ylim([2 4.8 ])
SETplot(' Lx-Porb-NS-wind')



%% M2-Porb
plot_mass_tb_gedian(allinall,xge,yge);
xlim([0 2])
ylim([-2 4.5])
SETplot(' M2-Porb-total')
plot_mass_tb_gedian(all_rb_1(all_rb_1(:,10)==14,:),xge,yge);
SETplot(' M2-Porb-BH-RLOF')

plot_mass_tb_gedian(all_wind_1(all_wind_1(:,10)==14,:),xge,yge);
SETplot(' M2-Porb-BH-wind')

plot_mass_tb_gedian(all_rb_1(all_rb_1(:,10)==13,:),xge,yge);
SETplot(' M2-Porb-NS-RLOF')

plot_mass_tb_gedian(all_wind_1(all_wind_1(:,10)==13,:),xge,yge);
ylim([2 4.8 ])
SETplot(' M2-Porb-NS-wind')


%% Lx-Porb
plot_lx_tb_gedian(allinall,xge,yge);
SETplot(' Lx-Porb-total')
plot_lx_tb_gedian(all_rb_1(all_rb_1(:,10)==14,:),xge,yge);
SETplot(' Lx-Porb-BH-RLOF')

plot_lx_tb_gedian(all_wind_1(all_wind_1(:,10)==14,:),xge,yge);
SETplot(' Lx-Porb-BH-wind')

plot_lx_tb_gedian(all_rb_1(all_rb_1(:,10)==13,:),xge,yge);
SETplot(' Lx-Porb-NS-RLOF')

plot_lx_tb_gedian(all_wind_1(all_wind_1(:,10)==13,:),xge,yge);
ylim([2 4.8 ])
SETplot(' Lx-Porb-NS-wind')

hold off




%% beaming factor

plot_beaming_gedian(all_rb_1);
SETplot('beaming factor')
% figure 5 log10(b) -- number of ULXs
%b < 1
ge=12;

NN=zeros(ge,1);

% bar([linspace(-1,-11,11),1],log10(NN))
% xlabel('log(b)')
% ylabel('log10(N)')

% plot_mass_tb_gedian(all_wind_1(all_wind_1(:,10)==14,:),50,yge,0);
% title('BlackHole(wind)')
% 
% plot_mass_tb_gedian(all_wind_1(all_wind_1(:,10)==13,:),50,yge,0);
% title('NeutronStar(wind)')
% 
% plot_mass_tb_gedian(all_rb_1(all_rb_1(:,9)==1,:),50,yge,0);
% title('BlackHole(rb)')
% 
% plot_mass_tb_gedian(all_rb_1(all_rb_1(:,10)==13,:),50,yge,0);
% title('NeutronStar(rb)')

function SETplot(picName)
hfig = gcf;
haxis = get(hfig,'CurrentAxes');
hp = get(haxis, 'Children');


% positioning
% set the box size
BoxDim = [6, 3]; 
BoxPos = [1, 1, BoxDim(1), BoxDim(2)];

set(haxis, ...
    'Units'              , 'inches',...
    'Position'           , BoxPos);
% set the figure size and position
pos = get(hfig, 'Position');
outerpos = get(haxis, 'OuterPosition');
set(haxis, 'OuterPosition',[0, 0, outerpos(3), outerpos(4)]);
% set(hfig, 'Position', [pos(1), pos(2), outerpos(3), outerpos(4)]);
% for paper position in the eps
set(hfig, 'PaperPositionMode', 'auto');

% title(picName);
set(gca,'FontName','Times New Roman','FontSize',20,'LineWidth',1.5);
set(gca, 'XMinorTick', 'on')
set(gca, 'YMinorTick', 'on')
print(gcf, '-djpeg', '-opengl', sprintf('-r%d',600), [picName,'.jpg']);

end